package web.User;

import service.UserService;
import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/intoServlet")
public class intoServlet extends HttpServlet {
    private final UserService service = new UserService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String usersname = request.getParameter("usersname");
        String name = request.getParameter("name");
        String passwd = request.getParameter("passwd");
        String repassword = request.getParameter("repassword");
        String sex = request.getParameter("sex");
        String work = request.getParameter("work");
        String[]  str1=  request.getParameterValues("hobby");
        String inter = String.join(",",str1);
        String remark = request.getParameter("remark");
        User user1 = service.insertoff(usersname);

        if (user1!=null){
            response.sendRedirect("lesson6/shibai.html");
            return;
        }
        User user=new User();
        user.setUsersname(usersname);
        user.setPassword(passwd);
        user.setName(name);
        user.setWork(work);
        user.setInterest(inter);
        user.setSex(sex);
        user.setRemark(remark);
        service.insertUser(user);
        response.sendRedirect("lesson6/login1.jsp");

    }

}
